package com.jeecg.p3.system.poster.service;

import com.jeecg.p3.system.poster.dao.ExamQuestionBankDao;
import com.jeecg.p3.system.poster.dao.ExamQuestionDao;
import com.jeecg.p3.system.poster.entity.ExamQuestion;
import com.jeecg.p3.system.poster.entity.ExamQuestionBank;
import com.jeecg.p3.system.util.UuidUtils;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @ClassName: ExamQuestionService
 * @Description: TODO 试卷数据处理层
 * @author: zhangxiao
 * @date: 2021年1月10日 下午7:29:38
 */
@Service
public class ExamQuestionService {
    @Resource
    private ExamQuestionDao dao;

    /**
     * 分页查询试卷
     * @param pageQuery
     * @return
     */
    public PageList<ExamQuestion> queryPageList(PageQuery<ExamQuestion> pageQuery) {
        PageList<ExamQuestion> result = new PageList<>();
        Integer itemCount = dao.count(pageQuery);
        PageQueryWrapper<ExamQuestion> wrapper = new PageQueryWrapper<>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<ExamQuestion> list = dao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据传参获取试卷数量
     * @param examQuestion
     * @return
     */
    public Integer count(ExamQuestion examQuestion) {
        PageQuery<ExamQuestion> pageQuery = new PageQuery<>();
        pageQuery.setQuery(examQuestion);
        return dao.count(pageQuery);
    }

    /**
     * 新增试卷信息
     * @param examQuestion
     */
    public void doAdd(ExamQuestion examQuestion) {
        examQuestion.setId(UuidUtils.getId());
        dao.insert(examQuestion);
    }

    /**
     * 根据id查询试卷信息
     * @param id
     * @return
     */
    public ExamQuestion findById(String id) {
        return dao.get(id);
    }

    /**
     * 根据传参获取试卷列表信息
     * @param examQuestion
     * @return
     */
    public List<ExamQuestion> findByParam(ExamQuestion examQuestion) {
        if(examQuestion == null) {
            examQuestion = new ExamQuestion();
        }
        return dao.findByParam(examQuestion);
    }

    /**
     * 编辑试卷信息
     * @param examQuestion
     */
    public void doEdit(ExamQuestion examQuestion) {
        dao.update(examQuestion);
    }

    /**
     * 删除试卷信息
     * @param examQuestion
     */
    public void doDelete(ExamQuestion examQuestion) {
        examQuestion.setStatus("0");
        dao.update(examQuestion);
    }
}
